package operations;

import entity.Student;
import entity.StudentList;

import java.util.Scanner;

// 添加学生信息
public class Add implements IOperation {

    @Override
    public Student work() {
        Scanner in = new Scanner(System.in);
        Student student = new Student();
        System.out.println("请输入学号: ");
        student.setId(in.next());
        // 查询有没有重复添加
        for (Student student1 : StudentList.getInstance()) {
            if (student1.getId().equals(student.getId())) {
                System.out.println("该学号已经存在, 不能重复添加!");
                return null;
            }
        }
        System.out.println("请输入姓名: ");
        student.setName(in.next());
        System.out.println("请输入年龄: ");
        student.setAge(in.nextInt());
        StudentList.getInstance().add(student);
        System.out.println("\n添加成功!");
        return student;
    }
}
